package com.sise.thread.多线程发送邮件案例;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * 作者：idea
 * 日期：2018/6/24
 * 描述：
 */
public class SendTools {

    private SendEmail sendEmail;


    public void sendToAll(int totalNums) throws ExecutionException, InterruptedException {
        ExecutorService es= Executors.newCachedThreadPool();
        List<Future> futureList=new ArrayList<>();
        for(int i=0;i<totalNums;i++){
            futureList.add( es.submit(new SendEmail()));
        }
        int success=0;
        for (Future future : futureList) {
            if(future.get().equals(true)){
                success++;
            }
        }
        if(success==totalNums){
            System.out.println("发送成功");
        }
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        SendTools st=new SendTools();
        st.sendToAll(4);
    }
}

